#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""Utility forms"""
from django import forms
from django.forms import ValidationError

class SearchField(forms.CharField):
    "Form field customized to do searches"
    def clean(self, value):
        "Condició de validació: Eliminam les paraules massa curtes"
        search_terms = value.lstrip()
        if len(search_terms) <3:
            raise ValidationError('No es pot cercar, la paraula és massa curta')
        else:
            return search_terms
 

class SearchForm(forms.Form):
    "Creates the search form in the public part"
    query = SearchField(max_length=30)

